<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>大事件-后台登录页</title>
  <link rel="stylesheet" type="text/css" href="css/reset.css" />
  <link rel="stylesheet" type="text/css" href="css/iconfont.css" />
  <link rel="stylesheet" type="text/css" href="css/main.css" />
  <!-- 引入bootstrap的css文件 -->
  <link rel="stylesheet" href="./libs/bootstrap/css/bootstrap.min.css" />
  <!-- 引入jq文件 -->
  <script src="./libs/jquery-1.12.4.min.js"></script>
  <!-- 引入bootstrap的js文件 -->
  <script src="./libs/bootstrap/js/bootstrap.min.js"></script>
  <!-- 导入接口管理文件 -->
  <script src="./libs/http.js"></script>
</head>

<body>
  <div class="main_wrap">
    <div class="header">
      <a href="#" class="logo"><img src="images/logo.png" alt="" /></a>
      <div class="copyright">
        CopyRight © 2019 深圳百秀信息技术股份有限公司<br />All Rights Reserved
      </div>
    </div>

    <div class="login_form_con">
      <div class="login_title"></div>
      <form class="login_form">
        <i class="iconfont icon-user"></i>
        <i class="iconfont icon-key"></i>
        <input type="text" class="input_txt" placeholder="邮箱/手机号" />
        <input type="password" class="input_pass" placeholder="密码" />
        <input type="submit" class="input_sub" value="登 录" />
      </form>
    </div>
  </div>
  <!-- bootstrap的模态框 -->
  <div class="modal fade" tabindex="-1" role="dialog" id="myModal">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
          <h4 class="modal-title">温暖的提示</h4>
        </div>
        <div class="modal-body">
          <p></p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-primary" data-dismiss="modal">
            确认
          </button>
        </div>
      </div>
      <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
  </div>
  <!-- /.modal -->
  <!-- <script>
      // 入口函数
      $(function () {
        // 给登录按钮设置点击事件
        $(".input_sub").on("click", function (e) {
          // 阻止提交按钮的默认效果
          e.preventDefault();
          // 1. 获得用户输入的邮箱以及密码
          let username = $(".input_txt").val().trim();
          let password = $(".input_pass").val().trim();

          // 2. 非空判断
          if (username == "" || password == "") {
            // alert('账户密码不能为空!');
            // 利用boostrap插件弹窗
            $("#myModal").modal();
            $(".modal-body>p").text("账户密码不能为空!");
            return;
          }

          // 3. 根据内容,发起ajax请求
          $.ajax({
            type: "post",
            url: BigNew.user_login,
            data: {
              username: username,
              password: password,
            },
            success: function (backData) {
              if (backData.code == 200) {
                // console.log(backData.token);
                // 5. 将登录成功返回的token令牌,保存到浏览器本地
                localStorage.setItem('bignews',backData.token);

                // alert('登录成功!');
                // 利用boostrap插件弹窗
                $("#myModal").modal();
                $(".modal-body>p").text("登录成功!");
                // 弹窗之后,点击关闭按钮后再跳转
                $("#myModal").on("hidden.bs.modal", function (e) {
                  // console.log('弹窗已经被隐藏');
                  // 4. 跳转到后台首页
                  window.location.href = "./index.html";
                })
              } else {
                // alert('账户或密码错误!');
                // 利用boostrap插件弹窗
                $("#myModal").modal();
                $(".modal-body>p").text("账户或密码错误!");
              }
            },
          });
        });
      });
    </script> -->
</body>

</html>
<script>
  $(function () {
    //登录按钮事件
    $(".input_sub").on("click", function (e) {
      e.preventDefault()
      let userName = $(".input_txt").val().trim()
      let passWord = $(".input_pass").val().trim()

      //发起请求，验证用户名与密码
      $.ajax({
        type: "post",
        url: BigNew.user_login,
        data: {
          username: userName,
          password: passWord
        },
        success: function (backData) {
          if (backData.code == 200) {
            $("#myModal").modal()
            $(".modal-body>p").text(backData.msg)
            localStorage.setItem("bigNews", backData.token)
            $("#myModal").on("hidden.bs.modal", function (e) {
              window.location.href = "./index.html"
            })
          } else {
            $("#myModal").modal()
            $(".modal-body>p").text(backData.msg)
          }
        }
      })
    })
  })
</script>